<template>
	<view class="wrap">
		<view class="key-input">
			<view class="title">输入验证码</view>
			<view class="tips">验证码已发送至 +86 {{account.mobile}}</view>
				<u-code-input
					v-model="code"
					mode="line"
					size="30"
					:maxlength="4"
					hairline
					color="#3c9cff"
					borderColor="#3c9cff"
					
					@finish="finishCode"
				></u-code-input>

			<text v-if="errCode" :class="{ error: error }">验证码错误，请重新输入</text>
			<view class="captcha">
				<text  v-if="getCode" style="color: #7468BE;" @tap="noCaptcha">收不到验证码点这里</text>
				<text  v-else >{{ second }}秒后重新获取验证码</text>
			</view>
		</view>
	</view>
</template>

<script>
var UserInfo = require('../../../service/UserInfo.js'),mUserInfo
	 
export default {
	data() {
		return {
			getCode:true,
			errCode:false,
			code:'',
			maxlength: 4,
			value: '',
			second: 60,
			show: false,
			error: false,
			account:{},
			isLoginPage : true
			
		};
	},
	computed: {},
	onLoad(ops) {
		let that = this
		mUserInfo = new UserInfo(this.mNetTool)
		// this.getCaptcha()
		let account ={
			password:ops.password,
			mobile:ops.mobile
		}
	 
		this.account= account
		let interval = setInterval(() => {
			this.second--;
			if (this.second <= 0) {
				this.getCode = true;
				if (this.value.lenth != 4) {
					this.error = true;
				}
				clearInterval(interval);
			}
		}, 1000);
	},
 
	methods: {
		finishCode(){
			 
			// if(this.code != 1234){
			// 	this.errCode = true
			// }else {
			// 	console.log(this.info)
				let info = {
					avatar:'https://servicetall.oss-cn-beijing.aliyuncs.com/saas/common/51aec15f510e491beadc848e4f0cc26ec2ec1137.png',
					level:'-1', 
					mobile:this.account.mobile,
					password:this.account.password,
					nick_name:'新用户',
				}
				this.mNetTool.getAjaxUrlValueBackground('capi/loomoSMS/checkCode',{
						mobile:this.account.mobile,
						code:this.code
				},res => {
					console.log(res)
					if(res.success){ 
						 mUserInfo.save(info,res => {
						 	console.log(res)
						 	if(res.success){
						 		info.id = res.id
								console.log('setStorageSync') 
						 		uni.navigateTo({
						 			url:'newUser?id='+res.id
						 		})
						 	}
						 })
					}
				})
				
			
			// }
		},
		// 收不到验证码选择时的选择
		noCaptcha() {
			
			uni.showActionSheet({
				itemList: ['重新获取验证码'],
				success: function(res) {
					
					this.mNetTool.getAjaxUrlValueBackground('capi/loomoSMS/getCode',{
							mobile:this.account.mobile,
							signature:'商品过期管家'
					},res => {
						console.log(res)
						if(res.success){
							this.getCode = false 
						}else {
							uni.$u.toast('验证码错误')
						}
					})
				},
				fail: function(res) {
					
				}
			});
		},
		// change事件侦听
		change(value) {
			// console.log('change', value);
		},
		// 输入完验证码最后一位执行
		finish(value) {
			// console.log('finish', value);
		}
	}
};
</script>

<style lang="scss" scoped>
.wrap {
	padding: 80rpx;
}

.box {
	margin: 30rpx 0;
	font-size: 30rpx;
	color: 555;
}

.key-input {
	padding: 30rpx 0;
	text {
		display: none;
	}
	.error {
		display: block;
		color: red;
		font-size: 30rpx;
		margin: 20rpx 0;
	}
}

.title {
	font-size: 50rpx;
	color: #333;
}

.key-input .tips {
	font-size: 30rpx;
	color: #333;
	margin-top: 20rpx;
	margin-bottom: 60rpx;
}
.captcha {
	// color: $u-type-warning;
	font-size: 30rpx;
	margin-top: 40rpx;
	.noCaptcha {
		display: block;
	}
	.regain {
		display: block;
	}
}
</style>
